import Types from '../../action/types'

const defaultState = {}

/**
 * state树结构
 * favorite:{
 *   popular:{
 *     projectModels:[],
 *     isLoading:false
 *   },
 *   trending:{
 *     projectModels:[],
 *     isLoading:false
 *   }
 * }
 *
 */
export default function onAction(state = defaultState, action) {
	switch (action.type) {
		//获取数据
		case Types.FAVORITE_LOAD_DATA:
			return {
				...state,
				[action.storeName]: {
					...state[action.storeName],
					projectModels: action.projectModels,
					isLoading: true
				}
			}
		//下拉刷新失败
		case Types.FAVORITE_LOAD_FAIL:
			return {
				...state,
				[action.storeName]: {
					...state[action.storeName],
					isLoading: false
				}
			}
		//下拉获取数据成功
		case Types.FAVORITE_LOAD_SUCCESS:
			return {
				...state,
				[action.storeName]: {
					...state[action.storeName],
					projectModels: action.projectModels,
					isLoading: false
				}
			}
		default:
			return state
	}
}
